#ifndef _YEP_ENGINE_KEYBOARD_HANDLER_HPP
#define _YEP_ENGINE_KEYBOARD_HANDLER_HPP

#include "../common.hpp"
#include <set>
#include <utility>

namespace yep
{
class KeyboardEvent;

/**
 * @brief Add a single key.
 **/
inline set<pair<SDLKey,SDLKey> > &addKey(set<pair<SDLKey,SDLKey> > & keyset, SDLKey key)
{
    keyset.insert({key, key});
    return keyset;
}

/**
 * @brief Add a key interval.
 *
 * It is both inclusive.
 **/
inline set<pair<SDLKey,SDLKey> > &addInterval(set<pair<SDLKey,SDLKey> > & keyset, SDLKey first, SDLKey last)
{
    keyset.insert({first, last});
    return keyset;
}

/**
 * @brief Handle keyboard events.
 **/
class KeyboardHandler
{
public:
    virtual ~KeyboardHandler(){}

    /**
     * @brief Return the keys to be tested to the evKeyPressed.
     *  Use the helpers addKey() and addInterval() to build it:
     *
     * @code
     **/
    virtual const set<pair<SDLKey,SDLKey> >&getKeySet() = 0;

    /**
     * @brief Occurs everytime a key is released.
     *
     * It can veto, which stops the propagation to other handlers.
     *  Older handlers receive the event before youngers.
     **/
    virtual void evKeyUp(KeyboardEvent &event){}

    /**
     * @brief Occurs everytime a key is pressed.
     *
     * It can veto, which stops the propagation to other handlers.
     *  Older handlers receive the event before youngers.
     **/
    virtual void evKeyDown(KeyboardEvent &event){}

    /**
     * @brief Occurs everytime it is holding a key .
     *
     * It can veto, which stops the propagation to other handlers.
     *  Older handlers receive the event before youngers.
     *
     * Only keys returned on keyset() method will be handled.
     **/
    virtual void evKeyPressed(KeyboardEvent &event){}
};

}

#endif // _YEP_ENGINE_KEYBOARD_HANDLER_HPP

